<%--
  Created by IntelliJ IDEA.
  User: hp
  Date: 2019/1/9
  Time: 9:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>销售退货</title>
    <jsp:include page="${pageContext.request.contextPath}/common/tag.jsp"/>
</head>
    <script>
        $(function () {
            $("#xstable").bootstrapTable({
                url : '${pageContext.request.contextPath}/xiaoshou/query', //路径
                toolbar : '#add,#pldel',
                pageSize : 8, //设置每页显示的行数
                pageList:[2,4,8,16], //设置可供选择的页面数据条数
                pageNumber:1, //如果设置了分页，首页页码。
                height : 400,  //表格高度
                pagination : true, //开启分页  默认情况下，是客户端分页的
                sidePagination:'server',  //启用服务器端分页
                striped : true,
                queryParams:function(params){
                    var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                        limit: params.limit,  //页面大小
                        offset: params.offset, //页码
                        danhao : $("#danhao").val()
                    };
                    return temp;
                },
                columns : [
                    {field : 'dnumbers',title:'订单号',align:'center'},
                    {field : 'dnum',title:'购买总数量',align:'center'},
                    {field : 'dyingshou',title:'应收金额',align:'center'},
                    {field : 'dzhehou',title:'折后金额',align:'center'},
                    {field : 'dyouhui',title:'优惠金额',align:'center'},
                    {field : 'dshishou',title:'实收金额',align:'center'},
                    {field : 'member.name',title:'会员姓名',align:'center'},
                    {field : 'staff.yName',title:'销售员',align:'center'},
                    {field : 'ddate',title:'订单日期',align:'center'},
                    {field : 'beizhu',title:'备注',align:'center'},
                    {title:'操作',align:'center',
                        formatter: function (index,row,value) {
                            return  "<button onclick=\"tuihuo("+row.dnumbers+")\"  class=\"btn btn-primary\">退货</button>";
                        }
                    }
                ],
                onClickRow : function(row, $element){
                    var index = $element.data('index');
                    //$("#shoptable").bootstrapTable("uncheckAll");
                    //选中要修改的行
                    //$("#shoptable").bootstrapTable("check",index);
                    //console.log(row);
                    $.post('${pageContext.request.contextPath}/xiaoshou/getInfoBydanhao',{"danhao":row.dnumbers},function (data) {
                        $("#xsinfotable").bootstrapTable('load',data);
                    })
                }
            })

            $("#xsinfotable").bootstrapTable({
                url : '', //路径
                pageSize : 8, //设置每页显示的行数
                pageList:[2,4,8,16], //设置可供选择的页面数据条数
                pageNumber:1, //如果设置了分页，首页页码。
                height : 300,  //表格高度
                columns : [
                    {field : 'danhao',title:'订单号',align:'center'},
                    {field : 'dspid',title:'商品编号',align:'center'},
                    {field : 'dspname',title:'商品名称',align:'center'},
                    {field : 'dchima',title:'尺码',align:'center'},
                    {field : 'brand.bname',title:'品牌',align:'center'},
                    {field : 'dyanse',title:'颜色',align:'center'},
                    {field : 'fenlei.fname',title:'分类',align:'center'},
                    {field : 'ddjmoeny',title:'单价',align:'center'},
                    {field : 'dxsnum',title:'销售数量',align:'center'},
                    {field : 'dzjwmoeny',title:'金额',align:'center'},
                    {title:'操作',align:'center',
                        formatter: function (index,row,value) {
                            return  "<button onclick=\"dantui("+row.ddinfoid+")\"  class=\"btn btn-primary\">单退</button>";
                        }
                    }
                ]
            })
        })
    </script>
<body style="margin:20px 10px;overflow-y: hidden;">
    <div>
        <div class="form-group">
            <label for="" class="col-sm-1 control-label" style="margin-top: 10px;">订单号：</label>
            <div class="col-sm-3">
                <input type="text" id="danhao" class="form-control">
            </div>
            <button class="btn btn-primary" onclick="serch()">查询</button>
        </div>
        <table id="xstable"></table>

        <table id="xsinfotable"></table>
    </div>
</body>
<script>
    function serch() {
        //返回表格的 Options。
        var opts = $("#xstable").bootstrapTable("getOptions") ;
        var limit = opts.pageSize ;
        var offset = (opts.pageNumber-1) * limit;
        var danhao = $("#danhao").val();
        $.post("${pageContext.request.contextPath}/xiaoshou/query",{"danhao":danhao,'limit':limit,'offset':offset},function (data) {
            // var mydata = eval("("+data+")") ;
            //重新绑定表格数据
            $("#xstable").bootstrapTable('load',data) ;
        })
    }
</script>
<script>
    function tuihuo(danhao) {
        swal({
            title: "您确定要退掉这件商品吗",
            text: "退掉后将无法恢复，请谨慎操作！",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "退货",
            closeOnConfirm: false
        },function () {
            $.post("${pageContext.request.contextPath}/xiaoshou/tuiall",{"dingdan":danhao},function (data) {
                if(data.tui){
                    $("#xstable").bootstrapTable('load',data);
                    $("#xsinfotable").bootstrapTable('load',data.xsinfolist);
                    swal("提示信息", "批量删除成功!", "success");
                }
            })
        });
    }

    function dantui (id) {
        swal({
            title: "您确定要退掉这件商品吗",
            text: "退掉后将无法恢复，请谨慎操作！",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "退货",
            closeOnConfirm: false
        },function () {
            $.post("${pageContext.request.contextPath}/xiaoshou/dantui",{"id":id},function (data) {
                if(data.tui){
                    $("#xstable").bootstrapTable('load',data);
                    $("#xsinfotable").bootstrapTable('load',data.xsinfolist);
                    swal("提示信息", "批量删除成功!", "success");
                }
            })
        });
    }
</script>
</html>
